package com.zmn.oms.zmn.utils.open;

import com.alibaba.fastjson.JSON;
import com.google.common.collect.Maps;
import com.zmn.oms.common.utils.SignUtil;
import com.zmn.oms.model.dto.open.v2.PushOrderDTO;

import java.util.Map;

/**
 * 类描述：
 *
 * @author lhl
 * @date 2020/01/10 20:05
 */
public class OpenApiUtil {

    /**
     * 封装V2版接口请求参数
     * @param channelId
     * @param secretkey
     * @param funId
     * @param data
     * @return
     */
    public static Map<String, String> newV2RequestParams(int channelId, String secretkey, String funId,
                                                         PushOrderDTO data) {
        Map<String, String> params = Maps.newHashMap();
        params.put("appId", String.valueOf(channelId));
        params.put("jsonData", JSON.toJSONString(data));
        params.put("funId", funId);
        params.put("version", "2");
        params.put("timestamp", String.valueOf(unixTimestemp()));
        params.put("sign", SignUtil.signMd5(params, secretkey));

        return params;
    }

    /**
     * 生成UNIX时间戳
     * @return
     */
    private static Long unixTimestemp() {
        return System.currentTimeMillis() / 1000;
    }

    /**
     * 私有构造器，防止外部实例化
     */
    private OpenApiUtil() {}
}
